﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace EFSPWebParts
{
    [ToolboxItemAttribute(false)]
    public class ListViewNoHeader : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/EFSPWebParts/ListViewNoHeader/ListViewNoHeaderUserControl.ascx";

        #region properties

        private string _WebUrl = string.Empty;
        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("User Settings"),
        DisplayName("Site Relative Web URL"),
        WebDisplayName("Web Url"),
        WebDescription("Site Relative Web URL")]
        public string WebUrl
        {
            get { return _WebUrl; }
            set
            {
                _WebUrl = value;
            }
        }

        private string _ListViewUrl = string.Empty;
        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("User Settings"),
        DisplayName("Sub Site Relative URL of ListView"),
        WebDisplayName("List View Url"),
        WebDescription("Sub Site Relative URL of ListView")]
        public string ListViewUrl
        {
            get { return _ListViewUrl; }
            set
            {
                _ListViewUrl = value;
            }
        }

        private bool _ShowHeader = false;
        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("User Settings"),
        DisplayName("Show Header"),
        WebDisplayName("Show Header"),
        WebDescription("Show Header (true or false)")]
        public bool ShowHeader
        {
            get { return _ShowHeader; }
            set
            {
                _ShowHeader = value;
            }
        }

        private bool _CheckPermission = false;
        [WebBrowsable(true),
        Personalizable(PersonalizationScope.Shared),
        Category("User Settings"),
        DisplayName("Check Permission"),
        WebDisplayName("Check Permission"),
        WebDescription("Check Permission (true or false)")]
        public bool CheckPermission
        {
            get { return _CheckPermission; }
            set
            {
                _CheckPermission = value;
            }
        }

        #endregion

        protected override void CreateChildControls()
        {
            ListViewNoHeaderUserControl control = (ListViewNoHeaderUserControl)Page.LoadControl(_ascxPath);
            control.WebUrl = this.WebUrl;
            control.ListViewUrl = this.ListViewUrl;
            control.ShowHeader = this.ShowHeader;
            control.CheckPermission = this.CheckPermission;
            Controls.Add(control);
        }
    }
}
